import { ref } from 'vue';
import { getGildingUploadInfoApi } from '@/api/sj/productManagement/designerTakesOrders/index';

function useHotStampingVersion() {
    const { proxy } = getCurrentInstance() as ComponentInternalInstance;

    const stampingVisible = ref(false);
    const stampingObj = ref<any>();
    const acceptId = ref('');
    const customerName = ref('');

    /** 打开弹窗 */
    const handleBeReady = async (row: any) => {
        if (!row.acceptId) {
            proxy?.$modal.msgWarning('请先分配订单');
            return
        }
        acceptId.value = row.acceptId;
        customerName.value = row.customerName;
        await getDetails(row.id);
    };

    /** 提交成功的操作 */
    const handleStampingSubmit = (result: boolean, fun: Function) => {
        if (result) {
            fun();
        };
    };

    const getDetails = async (id: string) => {
        const { code, data } = await getGildingUploadInfoApi(id);
        if (code == 200) {
            if(data.flag == 1) {
                proxy?.$modal.msgWarning('请先上传烫金稿');
            }else {
                stampingObj.value = data.dataList
                stampingVisible.value = true;
            }
        }
    };

    /** 关闭弹窗 */
    const handleStampingClose = () => {
        stampingObj.value = {};
        stampingVisible.value = false;
    };

    return {
        stampingVisible,
        stampingObj,
        acceptId,
        customerName,
        handleBeReady,
        handleStampingSubmit,
        handleStampingClose
    };
};

export default useHotStampingVersion;